﻿#ifndef QQUICKVNCVIEWER_H
#define QQUICKVNCVIEWER_H

#include <QQuickItem>
#include <QQuickPaintedItem>
#include "qvncvieweradapter.h"
#include <QEvent>
#include <QKeyEvent>


class QQuickVncViewer : public QQuickPaintedItem
{
    Q_OBJECT
    Q_DISABLE_COPY(QQuickVncViewer)
    Q_PROPERTY(QString host READ host WRITE setHost)
    Q_PROPERTY(int port READ port WRITE setPort)
    Q_PROPERTY(QString password READ password WRITE setPassword)
    Q_PROPERTY(int serverWidth READ getServerWidth CONSTANT)
    Q_PROPERTY(int serverHeight READ getServerHeight CONSTANT)
    Q_PROPERTY(float imageScale READ getImageScale CONSTANT)

public:
    QQuickVncViewer(QQuickItem *parent = 0);
    ~QQuickVncViewer();

    QString host() const;
    void setHost(const QString &value);

    int port() const;
    void setPort(const int &value);

    QString password() const;
    void setPassword(const QString &value);

    int getServerWidth();

    int getServerHeight();

    float getImageScale();

    void paint(QPainter *painter);

    Q_INVOKABLE void start();
    Q_INVOKABLE void stop();
    Q_INVOKABLE void refresh();
    Q_INVOKABLE bool eventMyKey(int key, Qt::KeyboardModifiers modifiers, quint32 nativeScanCode,
                                const QString &text = QString(), bool autorep= false, int count = 1);
    Q_INVOKABLE void eventMyKey(const int myKey, const QString text, const bool pressed);

signals:
    void propChanged();
    void error(const QString errorString);
protected:
     bool event(QEvent *event);

public slots:
    void onUpdateRect(const QRect rect);
    void handlePropChanged();
    void onError(const QString errorString);
    void onDisconncet();
private:
    QString m_host;
    QString m_password;
    int m_port;
    bool m_recvDisConnect;
    QVncViewerAdapter  m_viewerAdapter;
};

#endif // QQUICKVNCVIEWER_H
